package org.example.spring05;

import org.example.spring05.config.EnvConfig;
import org.example.spring05.config.MyDataSource;
import org.example.spring05.controller.UserController;
import org.example.spring05.entity.Car;
import org.example.spring05.entity.Person;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.util.ResourceUtils;

import java.io.File;
import java.io.FileNotFoundException;
@SpringBootApplication
public class Spring05Application {
    public static void main(String[] args) throws FileNotFoundException {
        ApplicationContext context = SpringApplication.run(Spring05Application.class, args);

        Person person = context.getBean(Person.class);
        System.out.println(person);
        System.out.println(person.getName());

//        try {
//            Thread.sleep(100000);
//        } catch (InterruptedException e) {
//            throw new RuntimeException(e);
//        }

    }

    public static void main5(String[] args) throws FileNotFoundException {
        ApplicationContext context = SpringApplication.run(Spring05Application.class, args);

        MyDataSource dataSource = context.getBean(MyDataSource.class);
        System.out.println(dataSource);
    }





    public static void main4(String[] args) throws FileNotFoundException {
        ApplicationContext context = SpringApplication.run(Spring05Application.class, args);

        // 获取本地资源
        File file = ResourceUtils.getFile("classpath:application.properties");
        System.out.println(file.getAbsolutePath());
    }
    public static void main3(String[] args) {

        ApplicationContext context = SpringApplication.run(Spring05Application.class, args);
        Car car = context.getBean(Car.class);
        System.out.println(car);

//        String id = UUID.randomUUID().toString();
//        id = id.replaceAll("-", "");
//        System.out.println(id);

    }


    public static void main2(String[] args) {

        ApplicationContext context= SpringApplication.run(Spring05Application.class, args);
        EnvConfig bean = context.getBean(EnvConfig.class);
        System.out.println(  bean.getProperty());
    }
    public static void main1(String[] args) {

        ApplicationContext context= SpringApplication.run(Spring05Application.class, args);
        UserController userController = (UserController) context.getBean("userController");
        userController.add();
    }

}

